package leetcode.editor.cn;

import java.lang.reflect.InvocationTargetException;
import java.util.*;

public class _207_CourseSchedule {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {

        int[] myArray = {1, 2, 3};
        List myList = Arrays.asList(myArray);
        System.out.println(myList.size());//1
        System.out.println(myList.get(0));//数组地址值
//        System.out.println(myList.get(1));//报错：ArrayIndexOutOfBoundsException
        int[] array = (int[]) myList.get(0);
        System.out.println(array[0]);//1

    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public boolean canFinish(int numCourses, int[][] prerequisites) {
            List<List<Integer>> edges = new ArrayList<>();
            for (int i = 0; i < numCourses; i++) {
                edges.add(new ArrayList<>());
            }
            int[] indeg = new int[numCourses];
            for (int[] info : prerequisites) {
                edges.get(info[1]).add(info[0]);
                indeg[info[0]]++;
            }

            // 初始化入度为 0 的队列
            Queue<Integer> queue = new LinkedList<>();
            for (int i = 0; i < numCourses; i++) {
                if (indeg[i] == 0) {
                    queue.add(i);
                }
            }

            int visited = 0;
            while (!queue.isEmpty()) {
                visited++;
                int u = queue.peek();
                queue.remove();
                for (int v : edges.get(u)) {
                    indeg[v]--;
                    if (indeg[v] == 0) {
                        queue.add(v);
                    }
                }
            }

            return visited == numCourses;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}